package com.yuncheng.spcyApi.controller;

import java.util.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.yuncheng.spcyApi.alog.annotation.Log;
import com.yuncheng.vo.HttpResult;
import com.yuncheng.common.query.QueryBuilder;
import com.yuncheng.utils.I18nUtil;
import com.yuncheng.common.base.controller.BaseController;
import com.yuncheng.spcyApi.entity.SpcyQyWjjl;
import com.yuncheng.spcyApi.service.ISpcyQyWjjlService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.yuncheng.system.api.SystemAPI;
import org.springframework.context.annotation.Lazy;

/**
 * @Description: 企业-文件记录
 * @Author: yuncheng
 * @Date: 2023-07-08
 * @Version: V1.0
 */
@Api(tags = "企业-文件记录接口")
@RestController
@RequestMapping("/api/spzx-spcy/spcyQyWjjl")
public class SpcyQyWjjlController extends BaseController<SpcyQyWjjl, ISpcyQyWjjlService> {

    private static final Logger log = LoggerFactory.getLogger(SpcyQyWjjlController.class);

    @Resource
    private ISpcyQyWjjlService spcyQyWjjlService;

    @Resource
    @Lazy
    private SystemAPI systemAPI;

    /**
     * 分页列表查询
     *
     * @param spcyQyWjjl
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @Log(title = "企业-文件记录-分页列表查询")
    @ApiOperation(value = "企业-文件记录-分页列表查询")
    @GetMapping(value = "/list")
    public HttpResult<?> queryPageList(SpcyQyWjjl spcyQyWjjl, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
        QueryWrapper<SpcyQyWjjl> queryWrapper = QueryBuilder.initQueryWrapper(spcyQyWjjl, req.getParameterMap());
        Page<SpcyQyWjjl> page = new Page<>(pageNo, pageSize);
        IPage<SpcyQyWjjl> pageList = spcyQyWjjlService.page(page, queryWrapper);
        for(SpcyQyWjjl vo:pageList.getRecords()){
            formatValue(vo);
        }
        return HttpResult.ok(pageList);
    }



    /**
     * 添加
     *
     * @param spcyQyWjjl
     * @return
     */
    @Log(title = "企业-文件记录-添加")
    @ApiOperation(value = "企业-文件记录-添加")
    //@RequiresPermissions("SpcyQyWjjl:SpcyQyWjjl:add")
    @PostMapping(value = "/add")
    public HttpResult<?> add(@RequestBody SpcyQyWjjl spcyQyWjjl) {
        HttpResult<String> result = new HttpResult(true);
        spcyQyWjjlService.save(spcyQyWjjl);
        result.setResult(spcyQyWjjl.getId());
        result.setMessage(I18nUtil.message("save.success"));
        return result;
    }

    /**
     * 编辑
     *
     * @param spcyQyWjjl
     * @return
     */
    @Log(title = "企业-文件记录-编辑")
    @ApiOperation(value = "企业-文件记录-编辑")
    //@RequiresPermissions("SpcyQyWjjl:SpcyQyWjjl:edit")
    @PutMapping(value = "/edit")
    public HttpResult<?> edit(@RequestBody SpcyQyWjjl spcyQyWjjl) {
        spcyQyWjjlService.updateById(spcyQyWjjl);
        return HttpResult.ok(I18nUtil.message("update.success"));
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @Log(title = "企业-文件记录-通过id删除")
    @ApiOperation(value = "企业-文件记录-通过id删除")
    //@RequiresPermissions("SpcyQyWjjl:SpcyQyWjjl:delete")
    @DeleteMapping(value = "/delete")
    public HttpResult<?> delete(@RequestParam("id") String id) {
        spcyQyWjjlService.removeById(id);
        return HttpResult.ok(I18nUtil.message("delete.success"));
    }

    /**
     * 通过id批量删除
     *
     * @param ids
     * @return
     */
    @Log(title = "企业-文件记录-批量删除")
    @ApiOperation(value = "企业-文件记录-批量删除")
    //@RequiresPermissions("SpcyQyWjjl:SpcyQyWjjl:delete")
    @DeleteMapping(value = "/deleteBatch")
    public HttpResult<?> deleteBatch(@RequestParam("ids") String ids) {
        spcyQyWjjlService.removeByIds(Arrays.asList(ids.split(",")));
        return HttpResult.ok(I18nUtil.message("delete.success"));
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @Log(title = "企业-文件记录-通过id查询")
    @ApiOperation(value = "企业-文件记录-通过id查询")
    @GetMapping(value = "/queryById")
    public HttpResult<?> queryById(@RequestParam("id") String id) {
        SpcyQyWjjl spcyQyWjjl = spcyQyWjjlService.getById(id);
        return HttpResult.ok(spcyQyWjjl);
    }

    /**
     * 导出excel
     */
    @Log(title = "企业-文件记录-导出excel")
    @ApiOperation(value = "企业-文件记录-导出excel")
    //@RequiresPermissions("SpcyQyWjjl:SpcyQyWjjl:export")
    @RequestMapping(value = "/exportExcel")
    public ModelAndView exportExcel(HttpServletRequest request,  SpcyQyWjjl spcyQyWjjl) {
    	return super.exportExcel(request, spcyQyWjjl, SpcyQyWjjl.class, "企业-文件记录");
    }

    /**
     * excel导入数据
     */
    @Log(title = "企业-文件记录-excel导入数据")
    @ApiOperation(value = "企业-文件记录-excel导入数据")
    //@RequiresPermissions("SpcyQyWjjl:SpcyQyWjjl:import")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public HttpResult<?> importExcel(HttpServletRequest request) {
    		return super.importExcel(request, SpcyQyWjjl.class);
    }

    /**
     * 数据转换
     * @param spcyQyWjjl
     */
    private void formatValue(SpcyQyWjjl spcyQyWjjl){
    }
}
